<style lang="less">
  // .main .content-wrapper {
  //   padding: 0;
  //   height: calc(100% - 80px);
  //   overflow: auto;
  // }
  .card_style {
    height: 100%;
    width: 100%;
    overflow: hidden;
    .ivu-card-body {
      padding: 0px;
    }
  }
  .page_style {
    margin-top: 10px;
    text-align: right;
  }
  .bench_search {
    margin-bottom: 10px;
  }
  .nopadding .ivu-table-cell {
    padding: 0px 0px;
  }
  .item1{
    height: 42px;
    line-height: 40px;
  }
</style>

<template>
  <Card class="card_style" :bordered="false" :dis-hover="true">
    <Row class="bench_search">
      <Col span="4">
        <span>全市：</span>
        <Select v-model="searchInfo.knowledge_type" style="width: 75%;">
          <Option value="沈阳市">沈阳市</Option>
        </Select>
      </Col>
      <Col span="4">
        <span>街道：</span>
        <Select v-model="searchInfo.knowledge_type" style="width: 75%;">
          <Option value="法律法规">法律法规</Option>
        </Select>
      </Col>
      <Col span="4">
        <span>社区：</span>
        <Select v-model="searchInfo.knowledge_type" style="width: 75%;">
          <Option value="法律法规">法律法规</Option>
        </Select>
      </Col>
      <Col span="4">
        <span>事项：</span>
        <Input style="width: 70%;" v-model="searchInfo.knowledge_title" />
      </Col>
      <Col span="4">
        <span>时间：</span>
        <DatePicker type="date" placeholder="Select date" style="width: 135px"></DatePicker>
      </Col>
      <Button icon="md-download" :loading="exportLoading" @click="exportExcel">导出文件</Button>
      <Button type="info" @click="searchData(false)"><Icon type="ios-search" /> 搜索</Button>
    </Row>
    <Table border :columns="columns1" :data="datalist"></Table>
    <Page :total="totalnum" :current="currentPageNo" :page-size="currentPageSize" @on-change="change" class="page_style"/>
  </Card>
</template>
<script>
import { knowledgeList, createKnowledge, getKnowledgeInfo, delKnowledge } from '@/api/eventlist'
import excel from '@/libs/excel'
export default {
  data () {
    return {
      exportLoading: false,
      modal: false,
      modal1: false,
      modal2: false,
      params: {
        pageNo: '',
        pageSize: ''
      },
      searchInfo: {
        knowledge_type: '',
        knowledge_title: ''
      },
      paramData: {
        knowledge_type: '',
        knowledge_title: '',
        knowledge_content: '',
        create_by: ''
      },
      paramData2: {
        knowledge_type: '',
        knowledge_title: '',
        knowledge_content: '',
        create_by: ''
      },
      currentPageNo: 1,
      currentPageSize: 10,
      selectstr: '',
      applyname: '',
      title: '',
      applytime: [],
      totalnum: 0,
      columns1: [
        { title: '序号', type: 'index', width: 70, align: 'center' },
        { title: '社区', key: 'knowledge_title', width: 150, align: 'center' },
        { title: '账号', key: 'create_by', width: 100, align: 'center' },
        { title: '事项名称', key: 'create_time', width: 175, align: 'center' },
        { title: '时间', key: 'create_by', width: 100, align: 'center' },
        { title: '办理状态', key: 'create_time', width: 100, align: 'center' },
        { title: '办理人姓名', key: 'create_time', width: 100, align: 'center' },
        { title: '办理人证件号', key: 'create_by', width: 150, align: 'center' },
        { title: '联系方式', key: 'create_time', width: 150, align: 'center' }
      ],
      datalist: [],
      modalInfo: {},
      company_list: [
        { id: 1, company_name: '演示社区1', company_code: 'L0002' },
        { id: 2, company_name: '演示社区2', company_code: 'LW12345' },
        { id: 3, company_name: '皇姑区明廉街道中海西社区', company_code: 'LA00690' },
        { id: 4, company_name: '沈河区山东庙街道三办南社区', company_code: 'LA00697' }
      ]
    }
  },
  computed: {
    companyCode () {
      return this.$store.state.user.severUserInfo.company_code
    }
  },
  methods: {
    exportExcel () {
      if (this.datalist.length) {
        this.exportLoading = true
        const params = {
          title: ['序号', '社区', '三级分类'],
          key: ['category1', 'category2', 'category3'],
          data: this.datalist,
          autoWidth: true,
          filename: '分类列表'
        }
        excel.export_array_to_excel(params)
        this.exportLoading = false
      } else {
        this.$Message.info('表格数据不能为空！')
      }
    },
    // 计算表达式的值
    evil (fn) {
      var Fn = Function
      return new Fn('return ' + fn)()
    },
    // 查询订单列表接口
    init (param) {
      param.pageNo = this.currentPageNo
      param.pageSize = this.currentPageSize
      knowledgeList(param).then(res => {
        console.log(res.data.data)
        if (res.data.errcode === 0) {
          this.datalist = res.data.data.results
          this.totalnum = res.data.data.totalRecord
        } else {
          this.$Notice.error({
            title: '获取知识库列表失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    ok111 (param) {
      createKnowledge(param).then(res => {
        console.log(res.data.errcode)
        if (res.data.errcode === 0) {
          this.init(this.params)
          this.$Notice.success({ title: '成功', desc: '' })
        } else {
          this.$Notice.error({ title: '失败', desc: res.data.errmsg })
        }
      })
    },
    showInfo (item) {
      this.modal1 = true
      console.log(item)
      var param = {
        id: item.id
      }
      getKnowledgeInfo(param).then(res => {
        console.log(res)
        if (res.data.errcode === 0) {
          this.paramData = res.data.data
          return
        }
        this.$Notice.error({ title: '数据获取失败', desc: res.errmsg })
      })
    },
    show (item) {
      this.modal = true
      console.log(item)
      var param = {
        id: item.id
      }
      getKnowledgeInfo(param).then(res => {
        console.log(res)
        if (res.data.errcode === 0) {
          this.paramData = res.data.data
          return
        }
        this.$Notice.error({ title: '数据获取失败', desc: res.errmsg })
      })
    },
    remove (item) {
      var param = {
        id: item.id
      }
      if (confirm('确定删除该条数据吗')) {
        delKnowledge(param).then(res => {
          console.log(res.data)
          if (res.data.errcode === 0) {
            this.init(this.params)
            return
          }
          this.$Notice.error({ title: '删除失败', desc: res.errmsg })
        })
      }
    },
    searchData (index) {
      let params = {
        knowledge_type: this.searchInfo.knowledge_type,
        knowledge_title: this.searchInfo.knowledge_title
      }
      this.currentPageNo = 1
      this.init(params)
    },
    change (pageNo) {
      this.currentPageNo = pageNo
      let params = {
        knowledge_type: this.searchInfo.knowledge_type,
        knowledge_title: this.searchInfo.knowledge_title
      }
      this.init(params)
    },
    // 修改订单信息
    updateInfo (item) {
      if (item.item_id === '11210101000000MZJD5212000330000') {
        this.$router.push({
          name: 'subsistenceapplication',
          params: {
            cardno: item.cardno,
            code: item.code
          }
        })
      } else {
        this.$router.push({
          name: 'handinformation',
          params: {
            itemid: item.item_id,
            cardno: item.cardno,
            code: item.code,
            cur_data: { tabindex: this.tab_index, pageNo: this.currentPageNo }
          }
        })
      }
    },
    // 弹出框功能，流程中需要填写信息的按钮
    popModal (item, modal, key) {
      this.modalInfo = {
        show: true,
        process_id: item.state,
        key: key,
        code: item.code,
        title: item.title + '-' + modal.name,
        params_type: modal.params_type,
        params_code: modal.params_code,
        next_process_id: modal.next_process_id,
        params_name: modal.params_name
      }
    },
    // 弹出框功能，填写信息后确定按钮
    acceptBtn () {
      let aaa = {
        code: this.modalInfo.code,
        key: this.modalInfo.key,
        state: this.modalInfo.process_id
      }
      if (this.modalInfo.params_code.indexOf('_') === 0) {
        aaa[this.modalInfo.params_code.substring(1)] = this.modalInfo.text
      } else {
        let params = {
          params_type: this.modalInfo.params_type,
          params_name: this.modalInfo.params_name,
          params_code: this.modalInfo.params_code,
          text: this.modalInfo.text
        }
        aaa.params = JSON.stringify(params)
      }
      setorderapply(aaa).then(res => {
        if (res.data.data) {
          this.init({ 'state': aaa.state })
          this.initTabCount()
        } else {
          this.$Notice.error({
            title: '获取事项列表失败',
            desc: res.data.errmsg
          })
        }
      })
    }
  },
  mounted () {
    // if (this.$route.params.pageNo) {
    //   this.currentPageNo = this.$route.params.pageNo
    // }
    this.init(this.params)
  }
}
</script>
